<template>
  <div class="app-container">
    <span>搜索内容：</span>
    <el-input style="width: 150px; padding: 10px" v-model="keyword" placeholder="请输入内容"></el-input>
    <el-button type="primary" round @click="handleSearch">搜索</el-button>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="ID" width="110">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="用户ID" width="150">
        <template slot-scope="scope">
          {{ scope.row.account }}
        </template>
      </el-table-column>
      <el-table-column label="技能名称" width="150">
        <template slot-scope="scope">
          {{ scope.row.skillName }}
        </template>
      </el-table-column>
      <el-table-column label="技能描述" width="200">
        <template slot-scope="scope">
          {{ scope.row.description }}
        </template>
      </el-table-column>
      <el-table-column label="技能等级" width="150">
        <template slot-scope="scope">
          {{ scope.row.grade }}
        </template>
      </el-table-column>
      <el-table-column label="价格(币)" width="150">
        <template slot-scope="scope">
          {{ scope.row.price }}
        </template>
      </el-table-column>
      <el-table-column label="认证图片" width="300" align="center">
        <template slot-scope="scope">
          <el-image
            style="width: 200px; height: 100px"
            :src="scope.row.imgUrls"
            :preview-src-list="[scope.row.imgUrls]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.status === 1 ? '审核通过' : '审核中' }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="创建时间" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time"/>
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="110" align="center">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status !== 1" size="mini" type="primary" round @click="dialogFormVisible = true; skillUser.userId=scope.row.userId; skillUser.userSkillId=scope.row.id">
            审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      background
      layout="prev, pager, next"
      :page-size="size"
      :current-page="page"
      :total="total"
      @current-change="fetchData">
    </el-pagination>

    <el-dialog title="技能审核" :visible.sync="dialogFormVisible">
      <el-radio v-model="status" label="1">通过</el-radio>
      <el-radio v-model="status" label="2">拒绝</el-radio>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleVerify">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getList, verifyUserSkill} from '@/api/userSkill'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      dialogFormVisible: false,
      list: null,
      listLoading: true,
      keyword: '',
      status: '1',
      skillUser: {
        userId: null,
        userSkillId: null
      },
      page: 1,
      size: 10,
      total: 0
    }
  },
  created() {
    this.fetchData(this.page)
  },
  methods: {
    fetchData(val) {
      this.page = val
      this.listLoading = true
      getList({page: this.page, size: this.size, keyword: this.keyword}).then(response => {
        this.total = response.total
        console.log(this.page)
        this.list = response.data
        this.listLoading = false
      })
    },
    handleSearch() {
      this.page = 1
      this.fetchData(this.page)
    },
    handleVerify() {
      this.dialogFormVisible = false
      verifyUserSkill({ userId: this.skillUser.userId, userSkillId: this.skillUser.userSkillId, status: this.status }).then(res => {
        this.fetchData(this.page)
        this.$message({
          type: 'success',
          message: '操作成功!'
        })
      })
    }
    // unDisabledUser(id) {
    //   unDisable(id).then(res => {
    //     this.fetchData(this.page)
    //     this.$message({
    //       type: 'success',
    //       message: '操作成功!'
    //     })
    //   })
    // }
  }
}
</script>
